<?php
declare(strict_types=1);

namespace App\Common\Modular\System\Traits\Configure\Traits;

use Core\Package\ElementPlus\FormCreate\FormItem;

/**
 * 密码规则管理
 */
trait PasswordForm
{

    /**
     * 后台账号密码规则
     * @param $configure
     * @return array
     */
    public function getAdmimpwdFormRule($configure): array
    {
        return $this->getPasswordForm($configure);
    }


    private function getPasswordForm($configure): array
    {
        return [
            FormItem::Number('min_length', '最低密码位数', $configure['min_length'] ?? 5)->min(5)->max(15)->required('请输入最低密码位数'),
            FormItem::Number('max_length', '最高密码位数', $configure['max_length'] ?? 6)->min(6)->max(30)->required('请输入最高密码位数'),
            FormItem::Checkbox('element', '密码组成部分', $configure['element'] ?? [])->options([
                ['label' => '数字', 'value' => 'number'],
                ['label' => '大写字母', 'value' => 'big_letter'],
                ['label' => '小写字母', 'value' => 'small_letter'],
                ['label' => '特殊字符', 'value' => 'symbol'],
            ])->hint('不选代表不限制,除了数字和字母都算特殊字符,勾选为必选,不勾选的可不选但也可选'),
        ];
    }
}